﻿using aier.dataaccess.dapper;
using aier.dataaccess.model;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.business.logic
{
    public class CustomerUserBll
    {
        public CustomerUserDal customerUserDal { get; set; }
        public ILog log { get; set; }
        public ResResult resResult { get; set; }

        /// <summary>
        /// 根据微信公众平台ID和用户对应OPENID查询客户绑定信息(select(String appId,String openId))
        /// </summary>
        /// <param name="appId">微信公众平台APPID</param>
        /// <param name="openId">微信用户对应微信公众平台唯一标识</param>
        /// <returns></returns>
        public CustomerUserView QueryCustomerByAppIdAndOpenId(string appId, string openId) {
            try
            {
                if (!string.IsNullOrWhiteSpace(appId) &&!string.IsNullOrWhiteSpace(openId))
                {
                  return customerUserDal.QueryCustomerByAppIdAndOpenId(appId, openId);
                    
                }
                else
                {
                    log.Error("QueryCustomerByAppIdAndOpenId 出现错误: appId或openId为空");
                    return null;
                }

            }
            catch (Exception e)
            {
                log.Error("QueryCustomerByAppIdAndOpenId方法错误：" + e.Message);
                return null;
            }
        }

        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="customerUserView"></param>
        /// <returns></returns>
        public ResResult SaveCustomerUser(CustomerUserView customerUserView) {
            Guid resultId = Guid.Empty;
            try {
                if (customerUserView==null) {
                    log.Error("SaveCustomerUser 出现错误：传入对象为空");
                    return resResult.FailResult("CustomerUserBll ->SaveCustomerUser : 传入实体为空");
                }
                return resResult.SuccessResult(customerUserDal.SaveCustomerUser(customerUserView));
            } catch (Exception e) {
                log.Error("SaveCustomerUser：" + e.Message);
                return resResult.FailResult("CustomerUserBll ->SaveCustomerUser Error: " + e.Message);
            }
           
        }
    }
}
